﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId", _state = "", _pstructId = "";
    var type = "@ViewBag.Type";
    var AuditSetting = "@ViewBag.AuditSetting";
    $(function () {
        InitialPage();
        GetTree1();
        GetTree2();
        GetGrid();
    });

    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 175.5);
            }, 200);
            e.stopPropagation();
        });

        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "选择组织机构",
            click: function (item) {
                debugger;
                _organizeid = item.id;
                GetTree2();
                SearchEvent();
            }
        });
        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);

        //时间
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
    }

    function GetTree1() {
        var item = {
            url: "../../PropertyManage/CS_Decorate/GetStateTreeList",
            onnodeclick: function (item) {
                _state = item.id;
                SearchEvent();
            }
        };
        $("#itemTree1").treeview(item);
    }

    function GetTree2() {
        var item = {
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&type=5&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                _pstructId = item.id;
                SearchEvent();
            }
        };
        $("#itemTree2").treeview(item);
    }

    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["PStructId"] = _pstructId;
        queryJson["OrganizeId"] = _organizeid;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Decorate/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "房间Id", name: "PStructId", hidden: true },
                {
                    label: "单据状态", name: "BillState", hidden: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return rowObject.State;
                    }
                },
                { label: "单据编号", name: "Code", index: "Code", width: 100, align: "left" },
                { label: "单据日期", name: "Date", index: "Date", width: 120, align: "left" },
                {
                    label: "房间名称", name: "PStructId", index: "PStructId", width: 150, align: "left"
                },
                { label: "申请人", name: "Cname", index: "Cname", width: 80, align: "left" },
                { label: "联系电话", name: "CLphone", index: "CLphone", width: 100, align: "center" },
                { label: "装修面积", name: "Area", index: "Area", width: 80, align: "left" },
                { label: "经营品牌", name: "Brand", index: "Brand", width: 120, align: "left" },
                { label: "施工单位", name: "ConstructionUnit", index: "ConstructionUnit", width: 120, align: "left" },
                {
                    label: "状态", name: "State", index: "State", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 1: {
                                return "<span style=\"color: #b91a1a;\">未提交,待确认提交</span>";
                            }; break;
                            case 2: {
                                return "<span style=\"color: #ec971f;\">立项审批中</span>";
                            }; break;
                            case 3: {
                                if (rowObject.IsHiddenChecked == 0) return "<span style=\"color: #5cb85c;\">隐蔽工程未验收</span>";
                                else if (rowObject.IsHiddenChecked == 1) return "<span style=\"color: #5cb85c;\">隐蔽工程验收中</span>";
                                else if (rowObject.IsHiddenChecked == 2) return "<span style=\"color: #5cb85c;\">隐蔽工程验收已完成</span>";
                                else return "<span style=\"color: #5cb85c;\">装修进行中</span>";
                            }; break;
                            case 4: {
                                if (rowObject.IsWholeChecked == 0) return "<span style=\"color: #5cb85c;\">整体工程未验收</span>";
                                else if (rowObject.IsWholeChecked == 1) return "<span style=\"color: #5cb85c;\">整体工程验收中</span>";
                                else return "<span style=\"color: #e89276;\">装修已结束</span>";
                            }; break;
                            case 5: {
                                if (rowObject.IsSecondChecked == 0) return "<span style=\"color: #5cb85c;\">二次验收未验收</span>";
                                else if (rowObject.IsSecondChecked == 1) return "<span style=\"color: #5cb85c;\">二次验收中</span>";
                                else return "<span style=\"color: #e89276;\">整体工程验收结束</span>";
                            }; break;
                            case 6: return "<span style=\"color: #e89276;\">二次验收已完成</span>"; break;
                        }
                    }
                },
                {
                    label: "操作", name: "State", index: "State", width: 200, align: "left",
                    formatter: function (cellvalue, options, rowObject) {

                        switch (cellvalue) {
                            case 1: {
                                return "<span onclick=\"btn_UploadFile(\'" + rowObject.Id + "\')\" class=\"label label-success\" style=\"cursor: pointer;background-color: #b91a1a;border: 1px solid #dad1d1;\"><i class='fa fa-plus'></i>&nbsp;提交装修单</span>";
                            } break;
                            case 2: {
                                return "<span onclick=\"btn_LookApproval(\'" + rowObject.ApprovalType + "\',\'" + rowObject.Id + "\',\'" + rowObject.ApprovalProcessId + "\')\" class=\"label label-success\" style=\"cursor: pointer;background-color:#ec971f;border: 1px solid #ec971f;\"><i class='fa fa-pencil-square-o'></i>&nbsp;查看/审批</span>";
                            }; break;
                            default: return ""; break;
                        }
                    }
                },
            { label: "备注", name: "Memo", index: "Memo", width: 200, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $(".ui-filter-text").trigger("click");
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
        });
        //查询重置事件
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            $("#Cname").val("");
            $("#Ccode").val("");
            $("#BCategory").val("");
        });
    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["PStructId"] = _pstructId;
        queryJson["OrganizeId"] = _organizeid;
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../PropertyManage/CS_Decorate/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加装修单',
            url: '/PropertyManage/CS_Decorate/Form',
            width: "1100px",
            height: "850px",
            btn: null
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑装修单',
                url: '/PropertyManage/CS_Decorate/Form?keyValue=' + keyValue + "&Type=" + type,
                width: "1100px",
                height: "850px",
                btn: null
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                msg: "是否确定删除，相关资料记录也会删除？该操作将无法恢复",
                url: "../../PropertyManage/CS_Decorate/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的单据！', 0);
        }
    }
    //材料配置
    function btn_MaterialSetting() {
        dialogOpen({
            id: "Form",
            title: '装修材料配置界面',
            url: '/PropertyManage/CS_MaterialSetting/MSettingForm?Type=1',
            width: "1100px",
            height: "850px",
            btn: null
        });
    }

    //装修审批流程配置
    function btn_FlowProcessSetting() {
        //dialogOpen({
        //    id: "FlowSchemeBuider",
        //    title: '审批流程创建',
        //    url: '/FlowManage/FlowDesign/Form?keyValue=system_flowid_01',
        //    width: "1100px",
        //    height: "700px",
        //    btn: null,
        //    callBack: function (iframeId) {
        //        top.frames[iframeId].AcceptClick();
        //    }
        //});
        if (!!AuditSetting) {
            dialogOpen({
                id: "WorkAuditSetting",
                title: '修改工单审核角色',
                url: '../../SystemManage/Setting/WorkAuditSetting?keyValue=' + AuditSetting,
                width: "700px",
                height: "550px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        } else { dialogMsg('不存在审批流程配置！', 0); }
    }

    //装修巡检配置
    function btn_PollingSetting() {
        dialogOpen({
            id: "ItemDetailIndex",
            title: '装修巡检项目配置',
            url: '/PropertyManage/CS_Polling/PollingSettingForm?type=' + type,
            width: "1100px",
            height: "700px",
            btn: null
        });
    }

    //装修验收配置
    function btn_InspectionSetting() {
        dialogOpen({
            id: "Form",
            title: '装修验收标准配置',
            url: '/PropertyManage/CS_Inspection/Index',
            width: "1100px",
            height: "700px",
            btn: null
        });
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 35%; overflow-y: auto; ">
            @*<div class="panel-Title">单据状态</div>*@
            <div id="itemTree1" style="height:100%;"></div>
        </div>
        <div class="west-Panel" style="height: 62.5%; overflow-y: auto;">
            <div class="panel-Title" style="height:28px;padding-left:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree2"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" type="text" value="@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">申请人名称</td>
                                                <td class="formValue">
                                                    <input id="Cname" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">申请人编号</td>
                                                <td class="formValue">
                                                    <input id="Ccode" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">经营品类</td>
                                                <td class="formValue">
                                                    <input id="BCategory" type="text" class="form-control">
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-more" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            <i class="fa fa-reorder"></i>&nbsp;装修配置<span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li id="lr-setting"><a onclick="btn_MaterialSetting()"><i></i>&nbsp;装修材料设置</a></li>
                            <li id="lr-Audit"><a onclick="btn_FlowProcessSetting()"><i></i>&nbsp;装修审批流程</a></li>
                            <li id="lr-polling"><a onclick="btn_PollingSetting()"><i></i>&nbsp;装修巡检设置</a></li>
                            <li id="lr-acceptance"><a onclick="btn_InspectionSetting()"><i></i>&nbsp;装修验收设置</a></li>
                        </ul>
                    </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
    @*<div class="ui-layout-east">
            <div class="east-Panel">
                <div class="panel-Title">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#panel1" data-toggle="tab">相关资料</a>
                        </li>
                        <li>
                            <a href="#panel2" data-toggle="tab">相关操作</a>
                        </li>
                    </ul>
                </div>
                <div class="tab-content">
                    <div class="tab-pane active" id="panel1">
                        <ul class="folder-list">
                            <li>
                                <a class="check-link">查看申请人资料</a>
                            </li>
                            <li>
                                <a class="check-link">查看财务记录</a>
                            </li>
                            <li>
                                <a class="check-link">查看巡检记录</a>
                            </li>
                            <li>
                                <a class="check-link">查看整改记录</a>
                            </li>
                            <li>
                                <a class="check-link">查看验收记录</a>
                            </li>

                        </ul>
                        <h5 style=" padding: 10px; background: #edf1f2; ">备注说明</h5>
                        <textarea style="width:100%;height:60px;"></textarea>
                        <div class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 10px 0;"></div>
                        <h5 style=" padding: 10px; background: #edf1f2; ">图档</h5>
                        <div style="border: 1px solid #cecece; height: 200px;">
                            <img />
                        </div>
                        <div class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 10px 0;"></div>


                    </div>
                    <div class="tab-pane" id="panel2">
                        <p>
                            Howdy, I'm in Section 2.
                        </p>
                    </div>

                </div>
            </div>
        </div>*@
    <style>
        .nav-tabs {
            padding-top: 1px;
        }

        .folder-list li {
            padding: 15px;
        }
    </style>
</div>
